package com.view.resourcemanage.CustomerFrame;

import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoTxt;
import com.service.CustomerService;
import com.service.impl.CustomerServiceImpl;
import com.util.MyCheckBox;
import com.view.MainFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CustomerAddDialog extends JDialog {

    private LovoButton addBtn;
    private LovoButton cancelBtn;
    private LovoTxt nameTxt,directorTxt,telTxt,emailTxt,addressTxt,rangeTxt;
    private MyCheckBox roleCbx;


    private MainFrame frame ;
    private CustomerService customerService = new CustomerServiceImpl();

    public CustomerAddDialog(MainFrame frame) {
        // TODO Auto-generated constructor stub
        super(frame,"添加新客户",true);
        this.frame = frame;
        this.setBounds(350, 250, 520, 400);
        this.setLayout(null);
        this.init();
        this.setVisible(true);

    }



    private void init() {
        // TODO Auto-generated method stub
        nameTxt = new LovoTxt("客户",20,20,this);
        directorTxt = new LovoTxt("负责人",20,90,this);
        telTxt = new LovoTxt("联系方式",20,160,this);
        emailTxt = new LovoTxt("邮箱",260,20,this);
        addressTxt = new LovoTxt("地址",260,90,this);
        rangeTxt = new LovoTxt("经营范围",260,160,this);

        this.addBtn = new LovoButton("添加", 120, 320, this);
        this.cancelBtn = new LovoButton("取消", 270, 320, this);

        addBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String nameTxtText = nameTxt.getText();
                String directorTxtText = directorTxt.getText();
                String telTxtText = telTxt.getText();
                String emailTxtText = emailTxt.getText();
                String addressTxtText = addressTxt.getText();
                String rangeTxtText = rangeTxt.getText();
                if(customerService.addCustomer(nameTxtText,directorTxtText,telTxtText,emailTxtText,addressTxtText,rangeTxtText)){
                    JOptionPane.showMessageDialog(null,"添加成功");
                    frame.flush();
                    frame.getsOMP().cmbFlush();
                    CustomerAddDialog.this.dispose();
                }else {
                    JOptionPane.showMessageDialog(null,"添加失败");
                }
            }
        });

    }


}
